package com.func.domain.credit.model.aggregate;

import com.func.domain.credit.model.entity.CreditAccountEntity;
import com.func.domain.credit.model.entity.CreditOrderEntity;
import com.func.domain.credit.model.entity.TaskEntity;
import com.func.domain.credit.model.valobj.TradeNameVO;
import com.func.domain.credit.model.valobj.TradeTypeVO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.math.BigDecimal;

/**
 * <p>
 * TradeAggregate
 * </p>
 *
 * @author Simon
 * @version 2025.03.23.1.0.0
 * @description 交易聚合对象
 * @since 2025-03-23
 */


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TradeAggregate {
    // 用户ID
    private String userId;
    // 积分账户实体
    private CreditAccountEntity creditAccountEntity;
    // 积分订单实体
    private CreditOrderEntity creditOrderEntity;
    // 任务实体, 补偿MQ消息
    private TaskEntity taskEntity;

    public static CreditAccountEntity createCreditAccountEntity(String userId, BigDecimal amount) {
        return CreditAccountEntity.builder().userId(userId).adjustAmount(amount).build();
    }

    public static CreditOrderEntity createCreditOrderEntity(String userId, TradeNameVO tradeName, TradeTypeVO tradeType, BigDecimal amount, String outBusinessNo) {
        return CreditOrderEntity.builder()
                .userId(userId)
                .tradeName(tradeName)
                .tradeAmount(amount)
                .outBusinessNo(outBusinessNo)
                .tradeType(tradeType)
                .orderId(RandomStringUtils.randomNumeric(12))
                .build();
    }

}
